#include <bits/stdc++.h>
using namespace std;
#define int long long

int n;
vector<int> edges[200005];

namespace CR200J {
	int h[200005], h2[200005];  // h2 一个交换的最大值
	void dfs(int i) {
		h[i] = 0;
		int mx1 = 0, mx2 = 0;
		for (auto j : edges[i]) {
			dfs(j);
			if (h[j] >= mx1) {
				mx2 = mx1;
				mx1 = h[j];
			} else if (h[j] >= mx2) {
				mx2 = h[j];
			}
			h[i] = max(h[i], h[j] + 1);
			h2[i] = max(h2[i], h2[j] + 1);
		}
		if (edges[i].size() >= 2) h2[i] = max(h2[i], mx1 + mx2 + 1);
	}
	void dfs2(int i, int &ans, int fas) {
		int mx1 = 0, mx2 = 0;
		for (auto j : edges[i]) {
			if (h[j] >= h[mx1]) {
				mx2 = mx1;
				mx1 = j;
			} else if (h[j] > h[mx2]) {
				mx2 = j;
			}
		}
		ans = max(ans, h2[i]);
		ans = max(ans, h[mx1] + 1 + max(h[mx2] + 1, fas));
		if (edges[i].size() >= 2) {
			ans = max(ans, h[mx1] + 1 + h[mx2] + 1 + fas);
		}
		for (auto j : edges[i]) {
			if (j == mx1) {
				ans = max(ans, h[mx2] + h2[j] + 2);
			} else {
				ans = max(ans, h[mx1] + h2[j] + 2);
			}
		}
		for (auto j : edges[i]) {
			if (j == mx1) {
				dfs2(j, ans, max(fas, h[mx2]));
			} else {
				dfs2(j, ans, max(fas, h[mx1]));
			}
		}
	}
	int solve() {
		h[0] = -2;
		dfs(1);
		int ans = 0;
		dfs2(1, ans, 0);
		return ans;
	}
	void main() {
		int lst = 0;
		for (int i = 2; i <= n; ++i) {
			int x;
			cin >> x;
			x ^= lst;
			if (x < 1 || x >= i) {
				cerr << "failed on t1\n";
				return;
			}
			edges[x].push_back(i);
			lst = solve();
			cout << lst << endl;
		}
	}
}

namespace CRH380D {
	int h[200005], h2[200005], mx1[200005], mx2[200005], fa[200005];  // h2 一个交换的最大值
	
	void dfs(int i, int &ans) {
		h[i] = 0;
		int mx1 = 0, mx2 = 0;
		for (auto j : edges[i]) {
			dfs(j, ans);
			if (h[j] >= h[mx1]) {
				mx2 = mx1;
				mx1 = j;
			} else if (h[j] >= h[mx2]) {
				mx2 = j;
			}
			h[i] = max(h[i], h[j] + 1);
			h2[i] = max(h2[i], h2[j] + 1);
		}
		if (edges[i].size() >= 2) h2[i] = max(h2[i], h[mx1] + h[mx2] + 1);
		ans = max(ans, h[mx1] + 1 + h[mx2] + 1);
		for (auto j : edges[i]) {
			if (j == mx1) {
				ans = max(ans, h[mx2] + h2[j] + 2);
			} else  {
				ans = max(ans, h[mx1] + h2[j] + 2);
			}
		}
	}
	int get_ans(int i) {
		h[0] = h2[0] = -2;
		h[i] = h2[i] = 0;
		mx1[i] = mx2[i] = 0;
		for (auto j : edges[i]) {
			if (h[j] >= h[mx1[i]]) {
				mx2[i] = mx1[i];
				mx1[i] = j;
			} else if (h[j] > h[mx2[i]]) {
				mx2[i] = j;
			}
			h[i] = max(h[i], h[j] + 1);
			h2[i] = max(h2[i], h2[j] + 1);
		}
		int ans = h2[i];
		assert(mx1[i] != mx2[i]);
		if (edges[i].size() >= 2) h2[i] = max(h2[i], h[mx1[i]] + h[mx2[i]] + 1);
		ans = max(ans, h[mx1[i]] + 1 + h[mx2[i]] + 1);
		if (mx1[i]) ans = max(ans, h[mx2[i]] + h2[mx1[i]] + 2);
		if (mx2[i]) ans = max(ans, h[mx1[i]] + h2[mx2[i]] + 2);
		return ans;
	}
	int solve(int x) {
		h[0] =  h2[0] = -2;
		int ans = 0;
		dfs(1, ans);
		return max(ans, h2[1]);
		/*
		while (x != 1 && x != 0) {
			//cout << "upd " << x << "\n";
	//		if (h[x] > h[mx1[fa[x]]]) {
	//			mx2[fa[x]] = mx1[fa[x]];
	//			mx1[fa[x]] = x;
	//		} else if (h[x] > h[mx2[fa[x]]] && x != mx1[fa[x]]) {
	//			mx2[fa[x]] = x;
	//		}
	//		h[fa[x]] = max(h[fa[x]], h[x] + 1);
	//		h2[fa[x]] = max(h2[fa[x]], h2[x] + 1);
			ans = max(ans, get_ans(fa[x]));
			x = fa[x];
		}
		return ans;*/
	}
	void main() {
		int lst = 0;
		for (int i = 2; i <= n; ++i) {
			int x;
			cin >> x;
			x ^= lst;
			if (x < 1 || x >= i || i == 15) {
				cerr << "failed on t2\n";
				return;
			}
			fa[i] = x;
			edges[x].push_back(i);
			lst = solve(i);
			cout << i << " : " << lst << endl;
		}
	}
}


signed main() {
	freopen("forest.in", "r", stdin); freopen("forest.out", "w", stdout);
	ios::sync_with_stdio(0); cin.tie(0);
	int id;
	cin >> id >> n;
	if (n <= 5000) CR200J::main();
	else for (int i = 1; i < n; ++i) cout << i << "\n";
	return 0;
}
